/*******************************************************************
 * Copyright (C) yel_hb-USTC, 2012                                
 *                                                                  
 * FILE NAME             :  kahansum.cpp                                 
 * PRINCIPAL AUTHOR      :  yel_hb                               
 * MODULE NAME           :  KAHANSUM                             
 * LANGUAGE              :  C++                                      
 * TARGET ENVIRONMENT    :  windows                                   
 * DATE OF FIRST RELEASE :  2012/12/14                              
 * DESCRIPTION           :  implementation the methods defined in 
 *							kahansum.h
 ******************************************************************/

/*
 * Revision log:
 *
 * Created by yel_hb,2012/12/14
 * Modified by yel_hb,2012/12/18
 *
 */

#include "kahansum.h"

KahanSum::KahanSum ()
{
	sum = 0;
	c = 0;
}

void KahanSum::reset()
{
	sum = 0;
	c = 0;
}

void KahanSum::add( double value )
{
	y = value - c;
	t = sum + y;
	c = t - sum - y;
	sum = t;
}

double KahanSum::get_sum()
{
	return sum;
}

KahanSum::~KahanSum()
{
	sum = 0;
}